package com.leyou.user.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import java.util.Date;

@Table(name = "tb_user")
@Data
public class User {
    @Id
    @KeySql(useGeneratedKeys = true)
    private Long id;            // 用户 id

    @NotEmpty(message = "用户名不能为空")
    @Length(min = 4, max = 32, message = "用户名长度必须在{min}-{max}之间")
    private String username;    // 用户名

    @NotEmpty(message = "密码不能为空")
    @Length(min = 4, max = 32, message = "密码长度必须在{min}-{max}之间")
    @JsonIgnore
    private String password;    // 密码 - 非对称加密

    @Pattern(
            regexp = "^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$",
            message = "手机号格式错误"
    )
    private String phone;       // 手机号

    private Date created;       // 创建时间

    @JsonIgnore
    private String salt;        // 加密用盐值
}
